package util

import "github.com/astaxie/beego/context"

var Ctx *context.Context

func OutPutInit(ctx *context.Context)  {
	Ctx = ctx
}

func OutPutSuccess(ret interface{})  {
	data := make(map[string]interface{}, 0)
	data["data"] = ret
	Ctx.Output.JSON(data,true,true)

}

func OutPutError(code int,msg string)  {
	Ctx.Output.SetStatus(code)
	data := make(map[string]interface{}, 0)
	data["errcode"] = code
	data["errmsg"] = msg
	Ctx.Output.JSON(data,true,true)
}

func CheckError(err error)  {
	if err != nil {
		OutPutError(401, err.Error())
	}
}